<template>
  <el-input-number v-model="vip_price" :min="0" :step="1" :precision="2" size="medium" @change="change" />
</template>

<script>
export default {
  props: {
    value: {
      type: Number,
      default: 0
    },
    formDatas: {
      type: Object,
      default: _ => {
        return {};
      }
    }
  },
  data() {
    return {
      vip_price: 0,
      edit: false
    };
  },
  watch: {
    vip_price(value) {
      this.$emit('update:value', value);
    },
    value: {
      handler(now, old) {
        this.vip_price = now;
      }
    },
    'formDatas.price': {
      handler(now, old) {
        if (!this.edit) {
          this.vip_price = now;
        }
      }
    }
  },
  created() {
    this.edit = this.$util.isDef(this.formDatas.vip_price);
    this.vip_price = this.edit ? this.value : 0;
  },
  methods: {
    change: function() {
      this.edit = true;
    }
  }
};
</script>

<style></style>
